package glue

import (
	"fmt"
	"math/rand"
)

const (
	DefaultVersion = "v0.0.0"

	DefaultUser   = "admin"
	DefaultUserId = "0"
	DefaultPasswd = "admin"
	DefaultGroup  = "Administrator"

	ConfigApplicationLevelGuaranteed = "guaranteed"
	ConfigApplicationLevelBurstAble  = "burstAble"
	ConfigApplicationLevelBestEffort = "bestEffort"

	ConfigStrategyBeatsLevelReadOnly  = "readonly"
	ConfigStrategyBeatsLevelReadWrite = "readwrite"

	ConfigKindApplication = "application"
	ConfigKindStrategy    = "strategy"
	ConfigKindBeats       = "beats"
)

type Config struct {
	Label      string `json:"label" yaml:"label" xorm:"label varchar(255) pk notnull unique"`
	Version    string `json:"version" yaml:"version" xorm:"version varchar(15) default 'v0.0.1'"`
	Name       string `json:"name" yaml:"name" xorm:"name varchar(40) default 'what is the config name?'"`
	Describe   string `json:"describe" yaml:"describe" xorm:"describe varchar(40) default 'what is the config describe?'"`
	ConfigKind string `json:"kind" yaml:"kind" xorm:"kind varchar(20) notnull default 'application'"`

	InstanceYaml       string `json:"instance_yaml" yaml:"instance_yaml" xorm:"instance_yaml TEXT"`
	InstanceServeLevel string `json:"instance_serve_level" yaml:"instance_serve_level " xorm:"instance_serve_level varchar(20) default 'bestEffort'"`
	InstanceType       string `json:"instance_type" yaml:"instance_type" xorm:"instance_type varchar(20) notnull default 'container'"`

	Tags string `json:"tags" yaml:"tags" xorm:"tags TEXT" `

	UserToken string `json:"user_token" yaml:"user_token" xorm:"user_token TEXT"`

	//UserName string `json:"user_name" yaml:"user_name"`
	//UserId   string `json:"user_id" yaml:"user_id"`
	//UserPasswd   string `json:"passwd" yaml:"passwd"`
	//UserGroup    string `json:"user_group" yaml:"user_group"`
}

func RandSuffix(n int) string {
	randBytes := make([]byte, n)
	_, _ = rand.Read(randBytes)
	return fmt.Sprintf("%x", randBytes)
}

func ConfigStrategyLevels() []string {
	return []string{ConfigStrategyBeatsLevelReadOnly, ConfigStrategyBeatsLevelReadWrite}
}

func ConfigKinds() []string {
	return []string{ConfigKindApplication, ConfigKindStrategy, ConfigKindBeats}
}

func ConfigApplicationLevels() []string {
	return []string{ConfigApplicationLevelBestEffort, ConfigApplicationLevelBurstAble, ConfigApplicationLevelGuaranteed}
}
